<?php

namespace App\Models;

use App\Models\System\Term;
use Illuminate\Database\Eloquent\Model;

class BasicInfoPosition extends Model
{
    protected $table = 'basic_info_position'; 
    protected $guarded = [];
    protected $hidden = [
        'created_at',
        'updated_at',
        'creator_id',
        'updater_id',
    ];
    protected $appends = [
        'title_set'
    ];

    public function term()
    {
        return $this->hasOne(Term::class, 'id', 'data_version_id');
    } 

    public function getTitleSetAttribute(){
        return $this->getFieldValue('title');
    }

    public function getFieldValue($field)
    {
        $f = !empty($this->attributes[$field]) ? $this->attributes[$field] : '';

        if(!$f){
            return [];
        }

        return json_decode($f, true);  
    }
}
